﻿
function isAllDigital(value)
{
    if(/\D/g.test(value))
      return false;
      return true;
}

function disableFormElement(formobj)
{
   collobj = formobj.elements;
   for(i=0;i<collobj.length;i++)
   {
         collobj(i).disabled = true;
   }
}

function _selectDate(obj){
  temp = obj.size - 8
  if(temp<=0){
        temp = 64 - -temp*6
  }else{
    temp = 64 + temp*6
  }
  showx = event.screenX - event.offsetX - temp ;
  showy = event.screenY - event.offsetY + 18;
  newWINwidth = 210 + 4 + 18;
  retval = window.showModalDialog("../common/calendar.htm","", "dialogWidth:292px; dialogHeight:187px; dialogLeft:"+showx+"px; dialogTop:"+showy+"px; status:no; directories:yes;scrollbars:no;resizable:no;help:no");
  if( retval != null ){
    obj .value = retval;
  }
}

  function selectRegisterDate(obj){
  temp = obj.size - 8
  if(temp<=0){
        temp = 64 - -temp*6
  }else{
    temp = 64 + temp*6
  }
  showx = event.screenX - event.offsetX - temp ;
  showy = event.screenY - event.offsetY + 18;
  newWINwidth = 210 + 4 + 18;
  retval = window.showModalDialog("../../common/calendar.htm","", "dialogWidth:292px; dialogHeight:187px; dialogLeft:"+showx+"px; dialogTop:"+showy+"px; status:no; directories:yes;scrollbars:no;resizable:no;help:no");
  if( retval != null ){
    obj .value = retval;
  }
}




var gdCtrl = new Object();
var gcGray = "#808080";
var gcToggle = "#ffff00";
var gcBG = "#FFFFFF";
var lnCE = "#FFFFFF";
var cmonth="",jiMonth="",jiDay="";

var gdCurDate = new Date();
var giYear = gdCurDate.getFullYear();
var giMonth = gdCurDate.getMonth()+1;
var giDay = gdCurDate.getDate();
var VicPopCal = new Object();

function selectDate(dataCtrl,strl, flag){
gdCtrl=dataCtrl;

x = getLeft(dataCtrl);
y = getTop(dataCtrl);
w = dataCtrl.offsetWidth;
h = dataCtrl.offsetHeight;


lw = document.all.jcalender03.offsetWidth;
lh = document.all.jcalender03.offsetHeight;


if(flag == 1){
	y = y-lh-h;
}

if(flag == 2){
	x = x+w;
	y = y-h;
}

W = document.body.scrollWidth;
H = document.body.scrollHeight;

cleft = x; ctop = y + h;

if(x + lw > W){
  cleft = x + w - lw;
}

if(y + lh > H){
  //ctop = y - lh;
}

document.all.jcalender03.style.pixelLeft=cleft;
document.all.jcalender03.style.pixelTop=ctop;
if(document.all.jcalender03.style.visibility=="hidden") {
    document.all.jcalender03.style.visibility="visible"; 
		showWindowedObjects(false)
}else {
    document.all.jcalender03.style.visibility="hidden";
		showWindowedObjects(true)
}
}

function fSetDate(iYear, iMonth, iDay){
  if(iMonth<10) jiMonth="0"+iMonth; else jiMonth=iMonth;
  if(iDay<10) jiDay="0"+iDay; else jiDay=iDay;
  gdCtrl.value = iYear+"-"+jiMonth+"-"+jiDay;
	showWindowedObjects(true);
	document.all.jcalender03.style.visibility = "hidden";
}

function fSetSelected(aCell){
  var iOffset = 0;
  var iYear = parseInt(tbSelYear.value);
  var iMonth = parseInt(tbSelMonth.value);

  aCell.bgColor = gcBG;
  with (aCell.children["cellText"]){
  	var iDay = parseInt(innerText);
  	if (color==gcGray)
		iOffset = (Victor<10)?-1:1;
	iMonth += iOffset;
	if (iMonth<1) {
		iYear--;
		iMonth = 12;
	}else if (iMonth>12){
		iYear++;
		iMonth = 1;
	}
  }
  fSetDate(iYear, iMonth, iDay);
}

function Point(iX, iY){
	this.x = iX;
	this.y = iY;
}

function fBuildCal(iYear, iMonth) {
  var aMonth=new Array();
  for(i=1;i<7;i++)
  	aMonth[i]=new Array(i);

  var dCalDate=new Date(iYear, iMonth-1, 1);
  var iDayOfFirst=dCalDate.getDay();
  var iDaysInMonth=new Date(iYear, iMonth, 0).getDate();
  var iOffsetLast=new Date(iYear, iMonth-1, 0).getDate()-iDayOfFirst+1;
  var iDate = 1;
  var iNext = 1;

  for (d = 0; d < 7; d++)
	aMonth[1][d] = (d<iDayOfFirst)?-(iOffsetLast+d):iDate++;
  for (w = 2; w < 7; w++)
  	for (d = 0; d < 7; d++)
		aMonth[w][d] = (iDate<=iDaysInMonth)?iDate++:-(iNext++);
  return aMonth;
}

function fDrawCal(iYear, iMonth, iCellWidth, iDateTextSize) {
  var WeekDay = new Array("Su","Mo","Tu","We","Th","Fr","Sa");
  var styleTD = "bgcolor='"+gcBG+"' width='"+iCellWidth+"' bordercolor='"+gcBG+"' valign='middle' align='center' style='font:10 Serif; font-size:9px'"; 
  with (document) {
    write("<tr>"); 
	for(i=0; i<7; i++)
        {
        if(i==0) cmonth="日";
        if(i==1) cmonth="一";
        if(i==2) cmonth="二";
        if(i==3) cmonth="三";
        if(i==4) cmonth="四";
        if(i==5) cmonth="五";
        if(i==6) cmonth="六";     
		write("<td "+styleTD+"color:#990099' >" + cmonth + "</td>");
        }
	write("</tr>");

  	for (w = 1; w < 7; w++) {
		write("<tr>");
		for (d = 0; d < 7; d++) {
			write("<td id=calCell "+styleTD+"cursor:hand;' onMouseOver='this.bgColor=gcToggle' onMouseOut='this.bgColor=gcBG' onclick='fSetSelected(this)'>");
			write("<font id=cellText Victor='Liming Weng'> </font>");
			write("</td>")
		}
		write("</tr>");
	}
  }
}

function fUpdateCal(iYear, iMonth) {
  myMonth = fBuildCal(iYear, iMonth);
  var i = 0;
  for (w = 0; w < 6; w++)
	for (d = 0; d < 7; d++)
		with (cellText[(7*w)+d]) {
			Victor = i++;
			if (myMonth[w+1][d]<0) {
				color = gcGray;
				innerText = -myMonth[w+1][d];
			}else{
				color = ((d==0)||(d==6))?"red":"black";
				innerText = myMonth[w+1][d];
			}
		}

}

function fSetYearMon(iYear, iMon){
  tbSelMonth.options[iMon-1].selected = true;
  for (i = 0; i < tbSelYear.length; i++)
	if (tbSelYear.options[i].value == iYear)
		tbSelYear.options[i].selected = true;
  fUpdateCal(iYear, iMon);
}

function fPrevMonth(){
  var iMon = tbSelMonth.value;
  var iYear = tbSelYear.value;

  if (--iMon<1) {
	  iMon = 12;
	  iYear--;
  }

  fSetYearMon(iYear, iMon);
}

function fNextMonth(){
  var iMon = tbSelMonth.value;
  var iYear = tbSelYear.value;

  if (++iMon>12) {
	  iMon = 1;
	  iYear++;
  }

  fSetYearMon(iYear, iMon);
}

function fGetXY(aTag){
  var oTmp = aTag;
  var pt = new Point(0,0);
  do {
  	pt.x += oTmp.offsetLeft;
  	pt.y += oTmp.offsetTop;
  	oTmp = oTmp.offsetParent;
  } while(oTmp.tagName!="BODY");
  return pt;
}

var gMonths = new Array("01","02","03","04","05","06","07","08","09","10","11","12");

with (document) {
write("<div id='jcalender03' style='cursor:hand;position:absolute;left:0;top:0;layer-background-color:#FFFFFF; z-index:1000;background-color: #CCCCCC;width:100;visibility:hidden;border:1px solid #bbd1e8;padding:0px'>");
write("<table id='popTable' style='cursor:hand;BORDER-RIGHT: #666666 1px solid; BORDER-TOP: #ffffff 1px solid; BORDER-LEFT: #ffffff 1px solid; BORDER-BOTTOM: #666666 1px solid'  border='0' bgcolor='#bbd1e8'>");
write("<TR>");
write("<td valign='middle' align='center'><input type='button' name='PrevMonth' value='<' style='cursor:hand;height:20;width:20;FONT:11' onClick='fPrevMonth()'>");
write("&nbsp;<SELECT name='tbSelYear' onChange='fUpdateCal(tbSelYear.value, tbSelMonth.value)' Victor='Won'>");
for(i=giYear+10;i>=2000;i--)
    {
    if(i==giYear) write("<OPTION value='"+i+"' selected>"+i+"</OPTION>");
    else    	  write("<OPTION value='"+i+"'>"+i+"</OPTION>");
    }
write("</SELECT>");
write("&nbsp;<select name='tbSelMonth' onChange='fUpdateCal(tbSelYear.value, tbSelMonth.value)' Victor='Won'>");
for (i=0; i<12; i++)
    {
    if(i+1==gMonths[giMonth-1]) 
       write("<option value='"+(i+1)+"' selected>"+gMonths[i]+"</option>");
    else                      
       write("<option value='"+(i+1)+"'>"+gMonths[i]+"</option>");
    }
write("</SELECT>");

write("&nbsp;<input type='button' name='PrevMonth' value='>' style='cursor:hand;height:20;width:20;FONT:11' onclick='fNextMonth()'>");
write("</td>");
write("</TR><TR>");
write("<td align='center'>");
write("<DIV style='background-color:"+lnCE+";'><table width='100%' border='0' cellpadding='2'>");
fDrawCal(giYear, giMonth, 19, 12);
write("</table></DIV>");
write("</td>");
write("</TR><TR><TD align='center'>");
write("<font style='cursor:hand;font:10' onclick='fSetDate(giYear,giMonth,giDay)' onMouseOver='this.style.color=gcToggle' onMouseOut='this.style.color=0'>今天:&nbsp;&nbsp;"+giYear+" 年 "+gMonths[giMonth-1]+"月"+giDay+"日</font>");
write("</TD></TR>");write("</TD></TR>");
write("</TABLE>");
write("</div>");
}
fUpdateCal(tbSelYear.value, tbSelMonth.value);

function getLeft(e){
  var t=e.offsetLeft;
  while(e=e.offsetParent)t+=e.offsetLeft;
  return t;
}

function getTop(e){
  var t=e.offsetTop;
  while(e=e.offsetParent)t+=e.offsetTop;
  return t;
}

function showWindowedObjects(show) {
		var windowedObjectTags = new Array("SELECT", "IFRAME", "OBJECT", "APPLET","EMBED");
		var windowedObjects = new Array();
		var j=0;
	
		for (var i=0; i<windowedObjectTags.length; i++) {
			var tmpTags = document.all.tags(windowedObjectTags[i]);
			
			if (tmpTags.length > 0) {
				for (var k=0; k<tmpTags.length; k++) {
					windowedObjects[j++] = tmpTags[k];
				}
			}
		}
	
		for (var i=0; i<windowedObjects.length; i++) {
		  if(windowedObjects[i].name == "tbSelMonth" || windowedObjects[i].name == "tbSelYear") continue;
			if (!show)
				windowedObjects[i].visBackup = (windowedObjects[i].style.visibility == null) ? "visible" : windowedObjects[i].style.visibility;
			windowedObjects[i].style.visibility = (show) ? windowedObjects[i].visBackup : "hidden";
		}
}

String.prototype.trim = function(){
    var reg = /^\s*(.*?)\s*$/;
    return this.replace(reg,"$1");
}

/**
 * 去掉数据的首尾空字符
 */
function jsTrim(value){
  return value.replace(/(^\s*)|(\s*$)/g,"");
}

/**
 * 校验数据是否为空（当数据为空字符时也为NULL）
 */ 
function isNULL( chars ) {
	if (chars == null)
		return true;
	if (jsTrim(chars).length==0)
		return true;
	return false;
}




/* 滑动移动对象, 渐渐的 滚动 效果, 可以控制对象在 X轴 或者 Y轴 滚动 */
function moveElement(elementID,final_x,final_y,interval)
{
    if (!document.getElementById) return false;
    if (!document.getElementById(elementID)) return false;
    var elem = document.getElementById(elementID);
    if (elem.movement) 
    {
        clearTimeout(elem.movement);
    }
    if (!elem.style.left) 
    {
        elem.style.left = "0px";
    }
    if (!elem.style.top) 
    {
        elem.style.top = "0px";
    }
    var xpos = parseInt(elem.style.left);
    var ypos = parseInt(elem.style.top);
    if (xpos == final_x && ypos == final_y) 
    {
        return true;
    }
    if (xpos < final_x) 
    {
        var dist = Math.ceil((final_x - xpos)/10);
        xpos = xpos + dist;
    }
    if (xpos > final_x) 
    {
        var dist = Math.ceil((xpos - final_x)/10);
        xpos = xpos - dist;
    }
    if (ypos < final_y) 
    {
        var dist = Math.ceil((final_y - ypos)/10);
        ypos = ypos + dist;
    }
    if (ypos > final_y) 
    {
        var dist = Math.ceil((ypos - final_y)/10);
        ypos = ypos - dist;
    }
    elem.style.left = xpos + "px";
    elem.style.top = ypos + "px";
    var repeat = "moveElement('"+elementID+"',"+final_x+","+final_y+","+interval+")";
    // alert(repeat);
    elem.movement = setTimeout(repeat,interval);

}















